<template>
  <n-data-table
    :columns="columns"
    :data="data"
    :pagination="false"
    :bordered="false"
    class="mt-4 mb-1 pb-1.5"
  />
</template>

<script lang="ts" setup>
  import { h, ref, onMounted } from 'vue';
  import { NTag } from 'naive-ui';
  import { ordernewlist } from '@/api/tongji/index';

  function toFixedPrice(value) {
    return parseFloat(value).toFixed(2);
  }

  const columns = ref([
    {
      title: '序号',
      key: 'serial',
      align: 'center',
      render: (_, index) => {
        return `${index + 1}`;
      },
    },
    {
      title: '会员ID',
      key: 'member_card',
      align: 'center',
    },
    {
      title: '门店名称',
      key: 'wdtitle',
      align: 'center',
    },
    {
      title: '设备号',
      key: 'charge_number',
      align: 'center',
    },
    {
      title: '订单金额',
      key: 'money',
      align: 'center',
      render(row) {
        return h(
          'span',
          {
            class: 'font-bold',
          },
          { default: () => (row.money != null ? `￥${toFixedPrice(row.money)}` : '') },
        );
      },
    },
    {
      title: '订单属性',
      key: 'attr',
      align: 'center',
      render(row) {
        if (row.attr == 1) {
          return h(
            NTag,
            {
              type: 'success',
            },
            {
              default: () => ('充电宝'),
            },
          );
        } else if (row.attr == 2) {
          return h(
            NTag,
            {
              type: 'info',
            },
            {
              default: () => ('充电盒子'),
            },
          );
        } else if (row.attr == 3) {
          return h(
            NTag,
            {
              type: 'warning',
            },
            {
              default: () => ('充电线'),
            },
          );
        }
      },
    },
    {
      title: '订单类型',
      key: 'member_id',
      align: 'center',
      render(row) {
        if (row.member_id == 0) {
          return h(
            NTag,
            {
              type: 'success',
            },
            {
              default: () => ('普通订单'),
            },
          );
        } else {
          return h(
            NTag,
            {
              type: 'info',
            },
            {
              default: () => ('会员订单'),
            },
          );
        }
      }
    },
    {
      title: '订单状态',
      key: 'status',
      align: 'center',
      render(row) {
        if (row.status == 0) {
          return h(
            NTag,
            {
              type: 'default',
            },
            {
              default: () => ('弹宝中'),
            },
          );
        } else if (row.status == 1) {
          return h(
            NTag,
            {
              type: 'primary',
            },
            {
              default: () => ('计费中'),
            },
          );
        } else if (row.status == 2) {
          return h(
            NTag,
            {
              type: 'primary',
            },
            {
              default: () => ('暂停计费'),
            },
          );
        } else if (row.status == 3) {
          return h(
            NTag,
            {
              type: 'success',
            },
            {
              default: () => ('待支付'),
            },
          );
        } else if (row.status == 4) {
          return h(
            NTag,
            {
              type: 'default',
            },
            {
              default: () => ('支付中'),
            },
          );
        } else if (row.status == 5) {
          return h(
            NTag,
            {
              type: 'info',
            },
            {
              default: () => ('已完成'),
            },
          );
        } else if (row.status == 6) {
          return h(
            NTag,
            {
              type: 'error',
            },
            {
              default: () => ('已取消'),
            },
          );
        } else if (row.status == 7) {
          return h(
            NTag,
            {
              type: 'warning',
            },
            {
              default: () => ('部分退款'),
            },
          );
        } else if (row.status == 8) {
          return h(
            NTag,
            {
              type: 'warning',
            },
            {
              default: () => ('全部退款'),
            },
          );
        } else if (row.status == 9) {
          return h(
            NTag,
            {
              type: 'warning',
            },
            {
              default: () => ('退款中'),
            },
          );
        } else if (row.status == 11) {
          return h(
            NTag,
            {
              type: 'warning',
            },
            {
              default: () => ('已购买'),
            },
          );
        } else if (row.status == 12) {
          return h(
            NTag,
            {
              type: 'warning',
            },
            {
              default: () => ('购宝待付款'),
            },
          );
        }
      },
    },
    {
      title: '平台',
      key: 'pingtai',
      align: 'center',
      render(row) {
        if (row.pingtai == 0) {
          return h(
            NTag,
            {
              type: 'info',
            },
            {
              default: () => ('微信小程序'),
            },
          );
        } else if (row.attr == 1) {
          return h(
            NTag,
            {
              type: 'success',
            },
            {
              default: () => ('抖音小程序'),
            },
          );
        } else if (row.attr == 2) {
          return h(
            NTag,
            {
              type: 'primary',
            },
            {
              default: () => ('支付宝小程序'),
            },
          );
        }
      }
    },
    {
      title: '时间',
      key: 'create_time',
      align: 'center',
    },
  ]);

  const data = ref([]);

  onMounted(async () => {
    const res1 = await ordernewlist({ });
    data.value = res1
  });

  
</script>
